#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
class Solution
{
public:
    int triangleNumber(vector<int>& nums)
    {
        sort(nums.begin(), nums.end());
        int sz = nums.size();
        int sum = 0;
        for (int i = sz - 1; i >= 2; i--)
        {
            int left = 0;
            int right = i - 1;
            while (left < right)
            {
                if (nums[left] + nums[right] > nums[i])
                {
                    sum += right - left;
                    right--;
                }
                else
                {
                    left++;
                }

            }
        }
        return sum;
    }
};

int main()
{
    vector<int> v{ 2,2,3,4 };
    Solution xz;
    int n = xz.triangleNumber(v);
    cout << n << endl;

	return 0;
}